//
//  MainViewController.swift
//  Weibo
//
//  Created by 张小东 on 16/1/10.
//  Copyright © 2016年 Mr.Zhang. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {
    @objc private func plusBtnDidClick() {
        //        print(__FUNCTION__)
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // 系统的tabbar 是只读属性 不能够直接修改
        // 可以使用kvc间接修改
        let mainTabbar = MainTabBar()
        setValue(mainTabbar, forKey: "tabBar")
        mainTabbar.plusBtn.addTarget(self, action: "plusBtnDidClick", forControlEvents: .TouchUpInside)
        
        
        //根控制器的入口
        addChildViewController()
        
        
    }
    
    private func addChildViewController()  {
        
        addChildViewControllers(HomeTableViewController(), imageName: "tabbar_home", title: "首页")
        addChildViewControllers(MessageTableViewController(), imageName: "tabbar_message_center", title: "消息")
        addChildViewControllers(DiscoveTableViewController(), imageName: "tabbar_discover", title: "发现")
        addChildViewControllers(ProfileTableViewController(), imageName: "tabbar_profile", title: "我")
        
        
    }
    
    // 添加子视图控制器
    
    private func addChildViewControllers(vc: UIViewController , imageName : String , title: String) {
        // 设置tabBar图片  并取消系统渲染
        vc.tabBarItem.image = UIImage(named: imageName)
        //        vc.tabBarItem.selectedImage = UIImage(named: imageName + "_highlighted")?.imageWithRenderingMode(.AlwaysOriginal)
        //        self.tabBar.tintColor = UIColor.orangeColor()
        //       vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: .Selected)
        //        vc.tabBarItem.title = title
        //        vc.navigationItem.title = title
        
        vc.title = title
        
        
        //        vc.tabBarItem.title = title
        // 实例化一个导航控制器
        let navVC = BaseNavViewController(rootViewController: vc)
        //        navVC.navigationBar.tintColor = UIColor.redColor()
        navVC.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName : UIColor.greenColor()]
        //    navVC.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登  陆", style: .Plain, target: self, action: "userWillLogin")
        
        // 添加子视图
        addChildViewController(navVC)
        
    }
    
    
}
